package com.bop.dehong.decaifu;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.View;

import com.bop.dehong.R;
import com.bop.dehong.base.DeHongApp;
import com.bop.dehong.base.TopManager;
import com.bop.dehong.config.Config;
import com.bop.dehong.decaifu.fragment.BasicInfo;
import com.bop.dehong.decaifu.fragment.Bidrecord;
import com.bop.dehong.decaifu.fragment.ProductIntroduct;
import com.bop.dehong.decaifu.fragment.Riskaudit;
import com.bop.dehong.login.LoginActivity;
import com.bop.dehong.main.BottomBarActivity;
import com.bop.dehong.main.BottomBarActivity.onBottomBarListener;


public class DeCaifuActivity extends BottomBarActivity implements onBottomBarListener {
	
	private List<Fragment> mFragments = new ArrayList<Fragment>();
	
	private BasicInfo mBasicInfo;
	private ProductIntroduct mProductIntroduct;
	private Riskaudit mRiskaudit;
	private Bidrecord mBidrecord;
	
	@Override
	protected List<Fragment> getFragments() {
		return mFragments;
	}

	@Override
	protected List<View> getBottomViews() {
		// TODO Auto-generated method stub
		List<View> bottoms = new ArrayList<View>();
		bottoms.add(getView(R.id.decaifu_home_bar));
		bottoms.add(getView(R.id.decaifu_category_bar));
		bottoms.add(getView(R.id.decaifu_shopping_cart_bar));
		bottoms.add(getView(R.id.decaifu_personal_center_bar));
		return bottoms;
	}

	@Override
	protected void initTop() {
		// TODO Auto-generated method stub
		super.initTop();
		View mView = getView(R.id.decaifu_top);
		TopManager manager = new TopManager(mView);
		manager.setTitle("详情页");
		manager.setLeftImageVisibility(View.VISIBLE);
	}
	
	@Override
	protected void initUI() {
		super.initUI();
		setBottomBarListener(this);
	}
	
	@Override
	protected void initFragments() {
		mBasicInfo = new BasicInfo();
		mProductIntroduct = new ProductIntroduct();
		mRiskaudit = new Riskaudit();
		mBidrecord = new Bidrecord();
		
		mFragments.add(mBasicInfo);
		mFragments.add(mProductIntroduct);
		mFragments.add(mRiskaudit);
		mFragments.add(mBidrecord);
	}

	
	@Override
	protected int getContentViewId() {
		return R.layout.caifu_top_bar;
	}

	private int position;
	
	@Override
	public boolean nBottomBar(int position) {
		if ((position == 2 || position == 3) && DeHongApp.mLoginEntity == null) {
			Intent intent = new Intent(this, LoginActivity.class);
			intent.putExtra(Config.GO_BACK, true);
			this.position = position;
			startActivityForResult(intent, 100);
			return true;
		}
		return false;
	}
	
	@Override
	protected void onActivityResult(int arg0, int resultCode, Intent arg2) {
		super.onActivityResult(arg0, resultCode, arg2);
		if (resultCode != RESULT_OK) {
			return;
		}
		if (arg0 == 100) {
			turnTargetView(position, false);
		}
	}
}
